﻿var columns =
            [
                 { display: 'Key', name: 'ID', type: 'text', hide: 1 },
                 { display: '商品类别', name: 'TypeName', mintWidth: 120, width: 160 },
                { display: '商品名称', name: 'ProductName', mintWidth: 100, width: 180 }, //, type: 'int', mintWidth: 40, width: 100
                {display: '商品编码', name: 'ProductCode', mintWidth: 80, width: 120 },
                { display: '商品规格', name: 'ProductStandard', mintWidth: 100, width: 220 },
                { display: '助记码', name: 'MnemonicCode',  mintWidth: 100, width: 100 },
                { display: '计量单位', name: 'refename', mintWidth: 80, width: 60 },
                { display: '销售单价(元)', name: 'SellPrice', mintWidth: 80, width: 80 },
              //  { display: '状态', name: 'DeleteState', mintWidth: 80, width: 120 },
                { display: '备注', name: 'Remarks', mintWidth: 150, width: 200 }
             ];

var manager;
$(document).ready(function () {
    $("#btnSearch").unbind("click").bind("click", initligerGrid);
    initligerGrid();
});

function initligerGrid() {
    manager = null;
    manager = $("#productsGrid").ligerGrid({
        columns: columns,
        title: '产品信息',
        showTitle: true,
        width: '100%',
        enabledSort: true,
        height: '99%',
        checkbox: false,
        rownumbers: true,
        toolbar: { items: [
                                    { text: '增加', click: dialogAdd, icon: 'add' },
                                    { line: true },
                                    { text: '修改', click: modifyOperation, icon: 'modify' },
                                    { line: true },
                                     { text: '工序', click: gxOperation, img: '../Content/images/edit2.png' }, //工序操作
                                    { line: true },
                                    { text: '删除', click: deleteOperation, img: '../Content/images/delete.gif' },
                                    { line: true },
                                    { text: '查看', click: dialogDetailView, img: '../Content/images/Search.png' }
                                    ]
        },
        parms: { orgCode: $("#HidOrgCode").val(), ProductName: $("#ProductName").val(), ProductCode: $("#ProductCode").val(), TypeName: $("#TypeName").val(), ProductGG: $("#ProductGG").val()},
        url: "../Product/GetJsonOfProducts?rand=" + Math.random(),
        onDblClickRow: function (data, rowindex, rowobj) { dialogView(data.ID); }
    });
}


//detail
function dialogDetailView() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择要查看的行!'); return; }
    var billId = row["ID"].toString();
    dialogView(billId);
 }
function dialogView(billId) {
    $.ligerDialog.open({ url: "../Product/Detail?id=" + billId, height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false });
}
//add
function dialogAdd() {
    $.ligerDialog.open({ url: '../Product/Add', height: getDialogHeight(), width: getDialogWidth(), 
    isResize: true, isHidden: false
    });
}

//delete
function deleteOperation() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择需要删除行！'); return; }
    $.ligerDialog.confirm('确定要删除吗？', function (yes) {
        if (yes) {
            $.get("../Product/Delete?id=" + row["ID"].toString(), {}, function (data) {
                if (data != undefined && data == "ok") {
                    initligerGrid();
                }
            });
        }
    });
}
//update 
function modifyOperation() {
    var row = manager.getSelectedRow();
    if (!row) {
        $.ligerDialog.success('请选择要编辑的行!'); return;
    }
    $.ligerDialog.open({ url: '../Product/Edit?id=' + row["ID"].toString(), height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false
    });
}
//工序 
function gxOperation() {
    var row = manager.getSelectedRow();
    if (!row) {
        $.ligerDialog.success('请选择要编辑的行!'); return;
    }
    $.ligerDialog.open({ url: '../ProductProcedure/Index?productId=' + row["ID"].toString(), height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false
    });
}


